package cn.jsj.onclock.controller;

import cn.jsj.onclock.interceptor.RequestThreadContext;
import cn.jsj.onclock.pojo.ClockEnt;
import cn.jsj.onclock.pojo.TaskEnt;
import cn.jsj.onclock.pojo.identity.ClockStatusEnum;
import cn.jsj.onclock.result.Result;
import cn.jsj.onclock.service.ClockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 卢斌
 */
@Controller
@CrossOrigin
@ResponseBody
@RequestMapping(value = "/clock")
public class ClockController {

    private final ClockService clockService;

    @Autowired
    public ClockController(ClockService clockService) {
        this.clockService = clockService;
    }


    /**
     * 用户打卡（签到签离）
     */
    @PutMapping(value = "/clock")
    public Result<String> clock(@RequestBody ClockEnt clockEnt) {
        Long userId = RequestThreadContext.requesterUserId();
        String resultStorage = clockService.userClock(userId, clockEnt.getLabelId(), clockEnt.getGuestbook());
        return Result.success(resultStorage);
    }


    /**
     * 用户查询自己的打卡信息
     */
    @GetMapping(value = "/clock", params = {"status", "pageNum", "pageSize"})
    public Result<ClockEnt> clockRecord(@RequestParam("status") ClockStatusEnum status, @RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        Long userId = RequestThreadContext.requesterUserId();
        List<ClockEnt> storage = clockService.listUserClockRecord(userId, status, pageNum, pageSize);
        return Result.success(storage);
    }


    /**
     * 查询此时通过标签卡可以完成的签到任务
     */
    @GetMapping(value = "/label_task", params = {"labelId"})
    public Result<TaskEnt> labelAboutTask(@RequestParam("labelId") Long labelId) {
        Long userId = RequestThreadContext.requesterUserId();
        List<TaskEnt> storage = clockService.listLabelCouldFinishTask(userId, labelId);
        return Result.success(storage);
    }
    

}
